import http from './commonAxios'
interface httpObj{
    baseURL:string,
    url:string,
    method:any,
    data?:any,
    headers:object
}
function request(state:number=8604,url:string,params:any,method:any,headers:string='application/json') {
    return new Promise((resolve:any,reject:any)=>{
        let  data = {};
        let baseURL='http://192.168.0.124:'+state;
        // if(process.env.NODE_ENV==='development'){
        //     baseURL = process.env.BASE_API+':'+state;
        //     //  baseURL = state===6200?process.env.BASE_API:state===6300?process.env.BASE_API1:state===6400?process.env.BASE_API2:state===6500?process.env.BASE_API3:process.env.BASE_API4
        // }else{
        //     baseURL = process.env.BASE_API;
        // }
        switch (method){
            case 'get': data={params};
                break;
            case 'post': data ={data:params};
                break;
            default: break;
        }
        let obj:httpObj = {
            baseURL,
            url,
            method,
            ...data,
            headers:{ 'Content-Type':headers },
        }
        http(obj).then((res)=>{
            resolve(res)
        }).catch(err=>{
            //提示错误r
            reject(err)
        })
    })
}

function get(state:number,url:string,params:any,headers:string) {
    return request(state,url,params,'get',headers);
}
function post(state:number,url:string,params:any,headers:string) {
    return request(state,url,params,'post',headers);
}
export default {
    get,post
}